package com.xpgk.mvc.statistic.dailySaleTotalStatistic;

import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.productPrice.Price;
import com.xpgk.mvc.productPrice.ProductPrice;
import com.xpgk.mvc.statistic.dailyTotalStatistic.DailyNursingTotal;

public class DailySaleTotalStatisticController  extends  BaseController{
	
	//private  DailySaleTotalStatisticServices   dailyTotalStatisticServices;
	
	public  void  index()
	{	
		String organids = getCUserOrganIds();
		Organization  organ = Organization.dao.findById(organids);
		setAttr("organization", organ);
		render("dailyTotalSaleStatistic.html");
	}
	@Before({Tx.class })
	public  void  getDailyTotal()
	{
		String month = getPara("month");
		String organids = getPara("organIds");
		String sql  = "SELECT *  from  sb_customer_total_daily  WHERE  organids = ?  AND  date LIKE ? ORDER BY date";
		List<DailyNursingTotal>  dntList =  DailyNursingTotal.dao.find(sql,organids,"%"+month+"%");
		double dyxslj = 0d;
		Organization organization = Organization.dao.findById(organids);
		Price price = Price.dao.findFirst("SELECT * FROM sb_shop_price WHERE organizationIds = ? ",organization.getStr(Organization.column_parentIds));
		String sql2 = "SELECT * FROM sb_product_price WHERE priceIds = ? AND productIds = ? ";
		double dlcdj = 0d;
		double bzlcdj = 0d;
		if(price!=null){
			ProductPrice dlcPrice = ProductPrice.dao.findFirst(sql2,price.getStr(Price.column_ids),Code.dlc_ids);
			ProductPrice bzlcPrice = ProductPrice.dao.findFirst(sql2,price.getStr(Price.column_ids),Code.bzlc_ids);
			dlcdj =  (double)dlcPrice.getFloat(ProductPrice.column_outPrice);
			bzlcdj = (double) bzlcPrice.getFloat(ProductPrice.column_outPrice);
		}
		
		for(int i = 0;i<dntList.size();i++){
			dyxslj = dyxslj+dntList.get(i).getDouble(DailyNursingTotal.column_priceTotal);
			dntList.get(i).set("dyxslj", dyxslj);
			dntList.get(i).set("rjdc",dlcdj);
			dntList.get(i).set("jzzxse", bzlcdj);
		}
		
		
		//添加旧数据到日综合查询表
//		dailyTotalStatisticServices.saveOld();
		renderJson(dntList);
	}
	
	
	/**
	 * 查询门店销售日报表（弹窗）
	 * */
	public  void queryDaily()
	{	
		String  organids=getPara("organids");
		Organization org = Organization.dao.findById(organids);
		setAttr("organization", org);	
		render("/dlstasticinfo/dailySaleTotal.html");
	}

}
